using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.Model;
using OgilvyOne.IDAL;
using OgilvyOne.Utility;
using System.Web.Configuration;

namespace OgilvyOne.SqlServerDAL
{
    public class SysMenu : ISysMenu, ITree
    {
        // Fields
        protected int currentmenuid;
        protected int DirCount;
        protected int[] DirList;
        protected int iCount;
        protected int jCount = 0;
        protected int menuuid = 0;
        protected int movecount = 1;
        private const string PARM_MENU_CREATE_DATE = "@Menu_Create_Date";
        private const string PARM_MENU_DISPLAY_NAME = "@Menu_Display_Name";
        private const string PARM_MENU_IS_LEAF = "@Menu_Is_Leaf";
        private const string PARM_MENU_ISDEL = "@IsDel";
        private const string PARM_MENU_LINK = "@Menu_Link";
        private const string PARM_MENU_NAME = "@Menu_Name";
        private const string PARM_MENU_PARENT_UID = "@Menu_Parent_UID";
        private const string PARM_MENU_SORD = "@Menu_Sord";
        private const string PARM_MENU_Tem_ID = "@Tem_ID";
        private const string PARM_MENU_UID = "@Menu_UID";
        private const string PARM_MENU_UPDATE_DATE = "@Menu_Update_Date";
        private const string PARM_MENU_VALID = "@Menu_Valid";
        private const string SQL_DELETE_MENU = "UPDATE Sys_Menu SET IsDel = '1' WHERE Menu_UID = @Menu_UID";
        private const string SQL_DELETE_MENU_INFO = "DELETE FROM Menu_Info WHERE Menu_ID = @Menu_UID";
        private const string SQL_INSERT_MENU = "INSERT INTO Sys_Menu (Menu_Parent_UID, Menu_Sord, Menu_Name, Menu_Display_Name, Menu_Link, Menu_Is_Leaf, Menu_Valid, menu_create_date, menu_update_date, isdel, tem_id,Tem_list_id,MENU_TYPE,Menu_out_url,target) VALUES(@Menu_Parent_UID,@Menu_Sord,@Menu_Name,@Menu_Display_Name,@Menu_Link,@Menu_Is_Leaf,@Menu_Valid,getDate(),null,'0',@Tem_ID,@Tem_list_id,@menu_type,@menu_out_url,@target)";
        private const string SQL_SELECT_MENU = "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date,Tem_ID,Tem_list_id,MENU_TYPE,isnull(Menu_out_url,''),isnull(target,'')  FROM Sys_Menu  where Menu_UID=@Menu_UID and IsDel='0'";
        private const string SQL_SELECT_MENU_CHILDLIST = "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Valid=@Menu_Valid and Menu_Parent_UID=@Menu_Parent_UID  and IsDel='0' Order by Menu_Sord ASC";
        private const string SQL_SELECT_MENU_CHILDLIST_ALL = "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Parent_UID=@Menu_Parent_UID and IsDel='0' Order by Menu_Sord ASC";
        private const string SQL_SELECT_MENU_COUNT = "SELECT count(Menu_UID) FROM Sys_Menu where Menu_Valid=@Menu_Valid and IsDel='0' Order by Menu_Sord ASC";
        private const string SQL_SELECT_MENU_LIST = "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Valid=@Menu_Valid and IsDel='0'";
        private const string SQL_SELECT_MENU_ROLE_CHILDLIST = "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Valid=@Menu_Valid and Menu_Parent_UID=@Menu_Parent_UID and menu_uid in ({0}) and IsDel='0' Order by Menu_Sord ASC";
        private const string SQL_SELECT_MENU_TREE = "select * from SYS_MENU where MENU_UID = @MENU_UID and IsDel='0'";
        private const string SQL_UPDATE_MENU = "UPDATE Sys_Menu SET Menu_Parent_UID = @Menu_Parent_UID, Menu_Sord = @Menu_Sord, Menu_Name = @Menu_Name, Menu_Display_Name = @Menu_Display_Name, Menu_Link = @Menu_Link, Menu_Is_Leaf = @Menu_Is_Leaf, Menu_Update_Date = getDate(), Menu_Valid = @Menu_Valid,Tem_ID=@Tem_ID,Tem_list_id=@Tem_list_id,MENU_TYPE=@menu_type,Menu_out_url=@menu_out_url,TARGET=@target WHERE Menu_UID = @Menu_UID";

        // Methods
        public void DeleteMenu(int node_id)
        {
            SqlParameter[] menuDeleteParameters = GetMenuDeleteParameters();
            menuDeleteParameters[0].Value = node_id;
            menuDeleteParameters[1].Value = "1";
            using (SqlConnection connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC))
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, "UPDATE Sys_Menu SET IsDel = '1' WHERE Menu_UID = @Menu_UID", menuDeleteParameters);
                        SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, "DELETE FROM Menu_Info WHERE Menu_ID = @Menu_UID", menuDeleteParameters);
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }

        public IList GetAllMenuList()
        {
            string cmdText = "select menu_uid, menu_parent_uid, menu_name, tem_id, tem_list_id, menu_type, menu_out_url, isnull(target, '_self') as target from sys_menu where isdel = '0'  order by menu_sord";
            IList list = new ArrayList();
            SysMenuInfo info = null;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, null))
            {
                while (reader.Read())
                {
                    info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    info.Tem_ID = reader.GetInt32(3);
                    info.Tem_list_ID = reader.GetInt32(4);
                    info.Menu_Type = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                    {
                        info.Menu_out_url = reader.GetString(6);
                    }
                    info.target = reader.GetString(7);
                    list.Add(info);
                }
            }
            return list;
        }

        public IList GetAllMenuList_Top()
        {
            string cmdText = "select menu_uid, menu_parent_uid, menu_name, tem_id, tem_list_id, menu_type, menu_out_url, isnull(target, '_self') as target from sys_menu where isdel = '0' and menu_uid in (select menu_id from menu_info where state=1) order by menu_sord";
            IList list = new ArrayList();
            SysMenuInfo info = null;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, null))
            {
                while (reader.Read())
                {
                    info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    info.Tem_ID = reader.GetInt32(3);
                    info.Tem_list_ID = reader.GetInt32(4);
                    info.Menu_Type = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                    {
                        info.Menu_out_url = reader.GetString(6);
                    }
                    info.target = reader.GetString(7);
                    list.Add(info);
                }
            }
            return list;
        }

        public IList GetAllMenuListByCache()
        {
            string key = "all_menu_key";
            IList allMenuList = HttpRuntime.Cache.Get(key) as IList;
            if (null == allMenuList)
            {
                allMenuList = this.GetAllMenuList();
                HttpRuntime.Cache.Insert(key, allMenuList, null, DateTime.Now.AddMinutes(30.0), TimeSpan.Zero);
            }
            return allMenuList;
        }

        public IList GetAllMenuListByCache_Top()
        {
            string key = "all_menu_key_top";
            IList list = HttpRuntime.Cache.Get(key) as IList;
            if (null == list)
            {
                list = this.GetAllMenuList_Top();
                HttpRuntime.Cache.Insert(key, list, null, DateTime.Now.AddMinutes(30.0), TimeSpan.Zero);
            }
            return list;
        }

        public IList GetAllMenuListSord(int parent_uid)
        {
            object obj2 = string.Concat(new object[] { "select menu_uid, menu_parent_uid, menu_name, tem_id, tem_list_id, menu_type, menu_out_url, isnull(target, '_self') as target ,a.sort as sort from dbo.lalel_config_info a,sys_menu s  where  a.menu_id=s.menu_uid and s.isdel=0 and a.status=0  and s.menu_parent_uid=", parent_uid, "  and a.menu_parent_id=", parent_uid }) + " union all";
            string cmdText = string.Concat(new object[] { obj2, " select menu_uid, menu_parent_uid, menu_name, tem_id, tem_list_id, menu_type, menu_out_url, isnull(target, '_self') as target,0 as sort from sys_menu where menu_uid not in(select menu_id from lalel_config_info where menu_parent_id=", parent_uid, ") and  menu_parent_uid=", parent_uid, " order by sort desc" });
            IList list = new ArrayList();
            SysMenuInfo info = null;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, null))
            {
                while (reader.Read())
                {
                    info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    info.Tem_ID = reader.GetInt32(3);
                    info.Tem_list_ID = reader.GetInt32(4);
                    info.Menu_Type = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                    {
                        info.Menu_out_url = reader.GetString(6);
                    }
                    info.target = reader.GetString(7);
                    list.Add(info);
                }
            }
            return list;
        }

        public int GetChildIDCount(int menu_uid)
        {
            string cmdText = "select menu_uid from dbo.GetChildCategories(" + menu_uid + ")";
            IList list = new ArrayList();
            int num = 0;
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    num += reader.GetInt32(0);
                }
            }
            return num;
        }

        public IList getChildNodeList(string isdel, int parent_node_id)
        {
            SqlParameter[] parameterArray;
            SqlDataReader reader;
            TreeInfo info;
            IList list = new ArrayList();
            if (isdel.Equals("0"))
            {
                parameterArray = new SqlParameter[] { new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4, "Menu_Parent_UID"), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1, "Menu_Valid") };
                parameterArray[0].Value = parent_node_id;
                parameterArray[1].Value = isdel;
                using (reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Valid=@Menu_Valid and Menu_Parent_UID=@Menu_Parent_UID  and IsDel='0' Order by Menu_Sord ASC", parameterArray))
                {
                    while (reader.Read())
                    {
                        info = new TreeInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(4), reader.GetString(3), reader.GetString(7), reader.GetString(6), reader.GetString(5));
                        list.Add(info);
                    }
                }
                return list;
            }
            parameterArray = new SqlParameter[] { new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4, "Menu_Parent_UID") };
            parameterArray[0].Value = parent_node_id;
            using (reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Parent_UID=@Menu_Parent_UID and IsDel='0' Order by Menu_Sord ASC", parameterArray))
            {
                while (reader.Read())
                {
                    info = new TreeInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(4), reader.GetString(3), reader.GetString(7), reader.GetString(6), reader.GetString(5));
                    list.Add(info);
                }
            }
            return list;
        }

        public int GetCnOrEnMenuId(string configName, int menuId)
        {
            int cnOrEnRootId = this.GetCnOrEnRootId(menuId);
            if (cnOrEnRootId == ConfigUtil.GetIntValue("en_vwcar_id"))
            {
                return ConfigUtil.GetIntValue("en_" + configName.ToLower());
            }
            if (cnOrEnRootId == ConfigUtil.GetIntValue("en_group"))
            {
                return ConfigUtil.GetIntValue("en_" + configName.ToLower());
            }
            return ConfigUtil.GetIntValue("cn_" + configName.ToLower());
        }

        public int GetCnOrEnRootId(int menuId)
        {
            return this.getRootID(menuId, ConfigUtil.GetIntValue("root_id"));
        }

        public int GetCnOrEnSubRootId(int menuId)
        {
            int cnOrEnRootId = this.GetCnOrEnRootId(menuId);
            return this.getRootID(menuId, cnOrEnRootId);
        }

        public string getCurrMenuTree(int Menu_UID, string page_name, string getENType)
        {
            this.DirCount = 0;
            this.DirList = new int[10];
            this.iCount = 1;
            int dirID = 0;
            this.jCount = this.iCount;
            int num = Menu_UID;
            this.currentmenuid = Menu_UID;
            this.menuuid = Menu_UID;
            int num3 = num;
            dirID = this.getRootID(Menu_UID, getENType);
            if (getENType == "EN")
            {
                dirID = this.getRootID(Menu_UID, "EN");
            }
            while (num3 != dirID)
            {
                IEnumerator enumerator = this.getMenu_idList(num3).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    this.DirCount++;
                    SysMenuInfo current = (SysMenuInfo)enumerator.Current;
                    this.DirList[this.DirCount] = current.Node_ID;
                    num3 = current.Parent_Node_ID;
                }
            }
            return this.ListDir1(dirID, page_name);
        }

        public IList getCurrNode(int nodeid)
        {
            IList list = new ArrayList();
            try
            {
                SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@Menu_Valid", SqlDbType.Char, 1, "Menu_IsDel"), new SqlParameter("@Menu_UID", SqlDbType.Int, 4, "Menu_UID") };
                cmdParms[0].Value = "0";
                cmdParms[1].Value = nodeid;
                using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date,Tem_ID,Tem_list_id,MENU_TYPE,isnull(Menu_out_url,''),isnull(target,'')  FROM Sys_Menu  where Menu_UID=@Menu_UID and IsDel='0'", cmdParms))
                {
                    while (reader.Read())
                    {
                        TreeInfo info = new TreeInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(4), reader.GetString(3), reader.GetString(7), reader.GetString(6), reader.GetString(5));
                        list.Add(info);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Write(exception.ToString());
            }
            return list;
        }

        public IList getDir_List(int DirID)
        {
            string cmdText = "select menu_uid,menu_parent_uid,menu_name from SYS_MENU where MENU_PARENT_UID=" + DirID + " and IsDel='0' order by Menu_UID";
            IList list = new ArrayList();
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    SysMenuInfo info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    list.Add(info);
                }
            }
            return list;
        }

        public IList GetGroupSubOrSelfTagMenuList(int menuId)
        {
            IList list = new ArrayList();
            SysMenuInfo sysMenuInfoById = this.GetSysMenuInfoById(menuId);
            if (null != sysMenuInfoById)
            {
                int parentMenuId = (sysMenuInfoById.Menu_Type == "1") ? sysMenuInfoById.Parent_Node_ID : menuId;
                IList subMenuList = this.GetSubMenuList(parentMenuId);
                if ((subMenuList == null) || (subMenuList.Count == 0))
                {
                    return list;
                }
                SysMenuInfo info2 = null;
                for (int i = 0; i < subMenuList.Count; i++)
                {
                    info2 = (SysMenuInfo)subMenuList[i];
                    if (info2.Menu_Type == "1")
                    {
                        list.Add(info2);
                    }
                }
            }
            return list;
        }

        private static SqlParameter[] GetItemParametersID()
        {
            SqlParameter[] cachedParameters = SQLHelper.GetCachedParameters("SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date,Tem_ID,Tem_list_id,MENU_TYPE,isnull(Menu_out_url,''),isnull(target,'')  FROM Sys_Menu  where Menu_UID=@Menu_UID and IsDel='0'");
            if (cachedParameters == null)
            {
                cachedParameters = new SqlParameter[] { new SqlParameter("@Menu_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Sord", SqlDbType.Int, 4), new SqlParameter("@Menu_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Display_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Link", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Is_Leaf", SqlDbType.Char, 1), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1), new SqlParameter("@Menu_Create_Date", SqlDbType.DateTime, 8), new SqlParameter("@Menu_Update_Date", SqlDbType.DateTime, 8) };
                SQLHelper.CacheParameters("SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date,Tem_ID,Tem_list_id,MENU_TYPE,isnull(Menu_out_url,''),isnull(target,'')  FROM Sys_Menu  where Menu_UID=@Menu_UID and IsDel='0'", cachedParameters);
            }
            return cachedParameters;
        }

        public string getLeftMenuName(int menu_uid)
        {
            string cmdText = "select menu_uid,menu_parent_uid,menu_name from SYS_MENU where menu_uid=" + menu_uid + " and isdel='0'";
            IList list = new ArrayList();
            string str2 = string.Empty;
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    str2 = str2 + reader.GetString(2);
                }
            }
            return str2;
        }

        public int getLeftMenuParentID(int menu_uid)
        {
            string cmdText = "select menu_uid,menu_parent_uid,menu_name from SYS_MENU where menu_uid=" + menu_uid + " and isdel='0'";
            IList list = new ArrayList();
            int num = 0;
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    num = reader.GetInt32(1);
                }
            }
            return num;
        }

        public IList getMenu_idList(int Menu_UID)
        {
            string cmdText = "select menu_uid,menu_parent_uid,menu_name,menu_type from SYS_MENU where menu_uid = " + Menu_UID + " and isdel='0'";
            IList list = new ArrayList();
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    SysMenuInfo info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    info.Menu_Type = reader.GetString(3);
                    list.Add(info);
                }
            }
            return list;
        }

        public int getMenuCount(string sValid)
        {
            int num = 0;
            try
            {
                SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@Menu_Valid", SqlDbType.Char, 1, "Menu_Valid") };
                cmdParms[0].Value = sValid;
                using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT count(Menu_UID) FROM Sys_Menu where Menu_Valid=@Menu_Valid and IsDel='0' Order by Menu_Sord ASC", cmdParms))
                {
                    while (reader.Read())
                    {
                        num = reader.GetInt32(0);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Write(exception.ToString());
            }
            return num;
        }

        private static SqlParameter[] GetMenuDeleteParameters()
        {
            SqlParameter[] cachedParameters = SQLHelper.GetCachedParameters("UPDATE Sys_Menu SET IsDel = '1' WHERE Menu_UID = @Menu_UID");
            if (cachedParameters == null)
            {
                cachedParameters = new SqlParameter[] { new SqlParameter("@Menu_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1) };
                SQLHelper.CacheParameters("UPDATE Sys_Menu SET IsDel = '1' WHERE Menu_UID = @Menu_UID", cachedParameters);
            }
            return cachedParameters;
        }

        private static SqlParameter[] GetMenuInsertParameters()
        {
            SqlParameter[] cachedParameters = SQLHelper.GetCachedParameters("INSERT INTO Sys_Menu (Menu_Parent_UID, Menu_Sord, Menu_Name, Menu_Display_Name, Menu_Link, Menu_Is_Leaf, Menu_Valid, menu_create_date, menu_update_date, isdel, tem_id,Tem_list_id,MENU_TYPE,Menu_out_url,target) VALUES(@Menu_Parent_UID,@Menu_Sord,@Menu_Name,@Menu_Display_Name,@Menu_Link,@Menu_Is_Leaf,@Menu_Valid,getDate(),null,'0',@Tem_ID,@Tem_list_id,@menu_type,@menu_out_url,@target)");
            if (cachedParameters == null)
            {
                cachedParameters = new SqlParameter[] { new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Sord", SqlDbType.Int, 4), new SqlParameter("@Menu_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Display_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Link", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Is_Leaf", SqlDbType.Char, 1), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1), new SqlParameter("@Tem_ID", SqlDbType.Int, 4), new SqlParameter("@Tem_list_id", SqlDbType.Int, 4), new SqlParameter("@menu_type", SqlDbType.VarChar, 1), new SqlParameter("@menu_out_url", SqlDbType.VarChar, 0xff), new SqlParameter("@target", SqlDbType.VarChar, 50) };
                SQLHelper.CacheParameters("INSERT INTO Sys_Menu (Menu_Parent_UID, Menu_Sord, Menu_Name, Menu_Display_Name, Menu_Link, Menu_Is_Leaf, Menu_Valid, menu_create_date, menu_update_date, isdel, tem_id,Tem_list_id,MENU_TYPE,Menu_out_url,target) VALUES(@Menu_Parent_UID,@Menu_Sord,@Menu_Name,@Menu_Display_Name,@Menu_Link,@Menu_Is_Leaf,@Menu_Valid,getDate(),null,'0',@Tem_ID,@Tem_list_id,@menu_type,@menu_out_url,@target)", cachedParameters);
            }
            return cachedParameters;
        }

        private static SqlParameter[] GetMenuModifyParameters()
        {
            SqlParameter[] cachedParameters = SQLHelper.GetCachedParameters("UPDATE Sys_Menu SET Menu_Parent_UID = @Menu_Parent_UID, Menu_Sord = @Menu_Sord, Menu_Name = @Menu_Name, Menu_Display_Name = @Menu_Display_Name, Menu_Link = @Menu_Link, Menu_Is_Leaf = @Menu_Is_Leaf, Menu_Update_Date = getDate(), Menu_Valid = @Menu_Valid,Tem_ID=@Tem_ID,Tem_list_id=@Tem_list_id,MENU_TYPE=@menu_type,Menu_out_url=@menu_out_url,TARGET=@target, MENU_ICON=@MENU_ICON, MENU_ICON1=@MENU_ICON1, MENU_ICON2=@MENU_ICON2, MENU_OTHER=@MENU_OTHER WHERE Menu_UID = @Menu_UID");
            if (cachedParameters == null)
            {
                cachedParameters = new SqlParameter[] { new SqlParameter("@Menu_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4), new SqlParameter("@Menu_Sord", SqlDbType.Int, 4), new SqlParameter("@Menu_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Display_Name", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Link", SqlDbType.VarChar, 0xff), new SqlParameter("@Menu_Is_Leaf", SqlDbType.Char, 1), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1), new SqlParameter("@Tem_ID", SqlDbType.Int, 4), new SqlParameter("@Tem_list_id", SqlDbType.Int, 4), new SqlParameter("@menu_type", SqlDbType.Int, 4), new SqlParameter("@menu_out_url", SqlDbType.VarChar, 0xff), new SqlParameter("@target", SqlDbType.VarChar, 50), new SqlParameter("@MENU_ICON", SqlDbType.VarChar, 50), new SqlParameter("@MENU_ICON1", SqlDbType.VarChar, 50), new SqlParameter("@MENU_ICON2", SqlDbType.VarChar, 50), new SqlParameter("@MENU_OTHER", SqlDbType.VarChar, 50) };
                SQLHelper.CacheParameters("UPDATE Sys_Menu SET Menu_Parent_UID = @Menu_Parent_UID, Menu_Sord = @Menu_Sord, Menu_Name = @Menu_Name, Menu_Display_Name = @Menu_Display_Name, Menu_Link = @Menu_Link, Menu_Is_Leaf = @Menu_Is_Leaf, Menu_Update_Date = getDate(), Menu_Valid = @Menu_Valid,Tem_ID=@Tem_ID,Tem_list_id=@Tem_list_id,MENU_TYPE=@menu_type,Menu_out_url=@menu_out_url,TARGET=@target, MENU_ICON=@MENU_ICON, MENU_ICON1=@MENU_ICON1, MENU_ICON2=@MENU_ICON2, MENU_OTHER=@MENU_OTHER WHERE Menu_UID = @Menu_UID", cachedParameters);
            }
            return cachedParameters;
        }

        public IList getMenuNode(int nodeid)
        {
            IList list = new ArrayList();
            try
            {
                SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@Menu_Valid", SqlDbType.Char, 1, "Menu_IsDel"), new SqlParameter("@Menu_UID", SqlDbType.Int, 4, "Menu_UID") };
                cmdParms[0].Value = "0";
                cmdParms[1].Value = nodeid;
                using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date,Tem_ID,Tem_list_id,MENU_TYPE,isnull(Menu_out_url,''),isnull(target,''),MENU_ICON,MENU_ICON1,MENU_ICON2,MENU_OTHER  FROM Sys_Menu  where Menu_UID=@Menu_UID and IsDel='0'", cmdParms))
                {
                    while (reader.Read())
                    {
                        SysMenuInfo info = new SysMenuInfo(reader.GetInt32(1), reader.GetString(7), reader.GetString(3), reader.GetString(4), reader.GetInt32(2), reader.GetString(5), reader.GetString(6));
                        info.Tem_ID = reader.GetInt32(10);
                        info.Tem_list_ID = reader.GetInt32(11);
                        info.Menu_Type = reader.GetString(12);
                        info.Menu_out_url = reader.GetString(13);
                        info.target = reader.GetString(14);
                        if (!reader.IsDBNull(15)) { info.MENU_ICON = reader.GetString(15); }
                        if (!reader.IsDBNull(16)) { info.MENU_ICON1 = reader.GetString(16); }
                        if (!reader.IsDBNull(17)) { info.MENU_ICON1 = reader.GetString(17); }
                        if (!reader.IsDBNull(18)) { info.MENU_OTHER = reader.GetString(18); }

                        list.Add(info);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Write(exception.ToString());
            }
            return list;
        }

        public IList GetNavigationList(int menuId, int siteRootId)
        {
            IList navigations = new ArrayList();
            if (menuId != siteRootId)
            {
                IList allMenuListByCache = this.GetAllMenuListByCache();
                SysMenuInfo smi = null;
                foreach (SysMenuInfo info2 in allMenuListByCache)
                {
                    if (info2.Node_ID == menuId)
                    {
                        smi = info2;
                    }
                }
                if (null != smi)
                {
                    this.SetNavigationList(allMenuListByCache, navigations, smi, siteRootId);
                }
            }
            return navigations;
        }

        public int getParentID(int menu_uid)
        {
            SysMenuInfo info = null;
            IList allMenuListByCache = this.GetAllMenuListByCache();
            foreach (SysMenuInfo info2 in allMenuListByCache)
            {
                if (info2.Node_ID == menu_uid)
                {
                    info = info2;
                }
            }
            if (null == info)
            {
                return menu_uid;
            }
            return info.iParent_Node_ID;
        }

        public int getParentID(int menu_uid, int siteRootId)
        {
            if (menu_uid == siteRootId)
            {
                return menu_uid;
            }
            SysMenuInfo info = null;
            IList allMenuListByCache = this.GetAllMenuListByCache();
            foreach (SysMenuInfo info2 in allMenuListByCache)
            {
                if (info2.Node_ID == menu_uid)
                {
                    info = info2;
                }
            }
            if ((null != info) && (info.Parent_Node_ID == siteRootId))
            {
                return info.Parent_Node_ID;
            }
            return 0;
        }

        public IList getRoleChildNodeList(string isdel, int parent_node_id)
        {
            SqlParameter[] parameterArray;
            SqlDataReader reader;
            TreeInfo info;
            IList list = new ArrayList();
            string str = HttpContext.Current.Session["MENU_KEY"].ToString();
            string cmdText = string.Format("SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Valid=@Menu_Valid and Menu_Parent_UID=@Menu_Parent_UID and menu_uid in ({0}) and IsDel='0' Order by Menu_Sord ASC", str);
            if (isdel.Equals("0"))
            {
                parameterArray = new SqlParameter[] { new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4, "Menu_Parent_UID"), new SqlParameter("@Menu_Valid", SqlDbType.Char, 1, "Menu_Valid") };
                parameterArray[0].Value = parent_node_id;
                parameterArray[1].Value = isdel;
                using (reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, parameterArray))
                {
                    while (reader.Read())
                    {
                        info = new TreeInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(4), reader.GetString(3), reader.GetString(7), reader.GetString(6), reader.GetString(5));
                        list.Add(info);
                    }
                }
                return list;
            }
            parameterArray = new SqlParameter[] { new SqlParameter("@Menu_Parent_UID", SqlDbType.Int, 4, "Menu_Parent_UID") };
            parameterArray[0].Value = parent_node_id;
            using (reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, "SELECT Menu_UID,Menu_Parent_UID,Menu_Sord,Menu_Name,Menu_Display_Name,Menu_Link,Menu_Is_Leaf,Menu_Valid,Menu_Create_Date,Menu_Update_Date FROM Sys_Menu where Menu_Parent_UID=@Menu_Parent_UID and IsDel='0' Order by Menu_Sord ASC", parameterArray))
            {
                while (reader.Read())
                {
                    info = new TreeInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(4), reader.GetString(3), reader.GetString(7), reader.GetString(6), reader.GetString(5));
                    list.Add(info);
                }
            }
            return list;
        }

        public IList getRoleMenu_idList(int Menu_UID)
        {
            string str = HttpContext.Current.Session["MENU_KEY"].ToString();
            string cmdText = string.Concat(new object[] { "select menu_uid,menu_parent_uid,menu_name from SYS_MENU where menu_uid = ", Menu_UID, " and menu_uid in('", str, "') and isdel='0'" });
            IList list = new ArrayList();
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    SysMenuInfo info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    list.Add(info);
                }
            }
            return list;
        }

        public int getRoleMenuParentID(int menu_uid)
        {
            string str = HttpContext.Current.Session["MENU_KEY"].ToString();
            string cmdText = string.Concat(new object[] { "select menu_uid,menu_parent_uid,menu_name from SYS_MENU where menu_uid=", menu_uid, " and menu_uid in('", str, "') and isdel='0'" });
            IList list = new ArrayList();
            int num = 0;
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    num = reader.GetInt32(1);
                }
            }
            return num;
        }

        public int getRootID(int menu_uid)
        {
            return this.getRootID(menu_uid, 1);
        }

        public int getRootID(int menu_uid, int siteRootId)
        {
            if (menu_uid == siteRootId)
            {
                return menu_uid;
            }
            SysMenuInfo info = null;
            IList allMenuListByCache = this.GetAllMenuListByCache();
            foreach (SysMenuInfo info2 in allMenuListByCache)
            {
                if (info2.Node_ID == menu_uid)
                {
                    info = info2;
                }
            }
            if (null == info)
            {
                return 0;
            }
            if (info.Parent_Node_ID != siteRootId)
            {
                this.SetNodeRootId(allMenuListByCache, siteRootId, ref info);
            }
            return info.Node_ID;
        }

        public int getRootID(int menu_uid, string getENType)
        {
            int siteRootId = 2;
            if (getENType == "EN")
            {
                siteRootId = 0x5d;
            }
            return this.getRootID(menu_uid, siteRootId);
        }

        public IList GetSubMenuList(int parentMenuId)
        {
            IList allMenuListByCache = this.GetAllMenuListByCache();
            IList list2 = new ArrayList();
            foreach (SysMenuInfo info in allMenuListByCache)
            {
                if (info.Parent_Node_ID == parentMenuId)
                {
                    list2.Add(info);
                }
            }
            return list2;
        }

        public IList GetSubMenuList_Top(int parentMenuId)
        {
            IList list = this.GetAllMenuListByCache_Top();
            IList list2 = new ArrayList();
            foreach (SysMenuInfo info in list)
            {
                if (info.Parent_Node_ID == parentMenuId)
                {
                    list2.Add(info);
                }
            }
            return list2;
        }

        public IList GetSubOrSelfMenuList(int parentMenuId)
        {
            IList allMenuListByCache = this.GetAllMenuListByCache();
            IList list2 = new ArrayList();
            foreach (SysMenuInfo info in allMenuListByCache)
            {
                if (!(((info.Parent_Node_ID != parentMenuId) && (info.iNode_ID != parentMenuId)) || info.Menu_Type.Equals("2")))
                {
                    list2.Add(info);
                }
            }
            return list2;
        }

        public IList GetSubOrSelfMenuListOther(int parentMenuId)
        {
            IList allMenuListByCache = this.GetAllMenuListByCache();
            IList list2 = new ArrayList();
            foreach (SysMenuInfo info in allMenuListByCache)
            {
                if (!((info.Parent_Node_ID != parentMenuId) || info.Menu_Type.Equals("2")))
                {
                    list2.Add(info);
                }
            }
            return list2;
        }

        public SysMenuInfo GetSysMenuDataByMID(int Menu_UID)
        {
            string cmdText = "select MENU_UID,MENU_PARENT_UID,MENU_NAME,MENU_DISPLAY_NAME,MENU_SORD,Tem_ID, MENU_ICON, MENU_ICON1, MENU_ICON2, MENU_OTHER from SYS_MENU where IsDel ='0' and MENU_UID = @MENU_UID";
            SysMenuInfo info = null;
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MENU_UID", SqlDbType.Int, 4) };
            cmdParms[0].Value = Menu_UID;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), reader.GetString(3));
                    info.Menu_Sord = reader.GetInt32(4);
                    info.Tem_ID = reader.GetInt32(5);
                }
            }
            return info;
        }

        public SysMenuInfo GetSysMenuInfoById(int menuId)
        {
            IList allMenuListByCache = this.GetAllMenuListByCache();
            foreach (SysMenuInfo info in allMenuListByCache)
            {
                if (info.Node_ID == 1050)
                {
                }
                if (info.Node_ID == menuId)
                {
                    return info;
                }
            }
            return null;
        }

        public string GetSysMenuNameById(int menuId)
        {
            SysMenuInfo sysMenuInfoById = this.GetSysMenuInfoById(menuId);
            if (null == sysMenuInfoById)
            {
                return string.Empty;
            }
            return sysMenuInfoById.Node_Name;
        }

        public IList GetTagMenuList(int menuId)
        {
            IList list = new ArrayList();
            SysMenuInfo sysMenuInfoById = this.GetSysMenuInfoById(menuId);
            if (null != sysMenuInfoById)
            {
                int parentMenuId = (sysMenuInfoById.Menu_Type == "1") ? sysMenuInfoById.Parent_Node_ID : menuId;
                IList subMenuList = this.GetSubMenuList(parentMenuId);
                if ((subMenuList == null) || (subMenuList.Count == 0))
                {
                    return list;
                }
                SysMenuInfo info2 = null;
                for (int i = 0; i < subMenuList.Count; i++)
                {
                    info2 = (SysMenuInfo)subMenuList[i];
                    if (info2.Menu_Type == "1")
                    {
                        list.Add(info2);
                    }
                }
            }
            return list;
        }

        public void InsertMenu(SysMenuInfo acc)
        {
            SqlParameter[] menuInsertParameters = GetMenuInsertParameters();
            this.SetMenuInsertParameters(menuInsertParameters, acc);
            using (SqlConnection connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC))
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, "INSERT INTO Sys_Menu (Menu_Parent_UID, Menu_Sord, Menu_Name, Menu_Display_Name, Menu_Link, Menu_Is_Leaf, Menu_Valid, menu_create_date, menu_update_date, isdel, tem_id,Tem_list_id,MENU_TYPE,Menu_out_url,target) VALUES(@Menu_Parent_UID,@Menu_Sord,@Menu_Name,@Menu_Display_Name,@Menu_Link,@Menu_Is_Leaf,@Menu_Valid,getDate(),null,'0',@Tem_ID,@Tem_list_id,@menu_type,@menu_out_url,@target)", menuInsertParameters);
                        transaction.Commit();
                    }
                    catch (SqlException exception)
                    {
                        transaction.Rollback();
                        Console.WriteLine(exception.Message);
                    }
                }
            }
        }

        public bool IsCnOrEnMenuByName(string configName, int menuId)
        {
            string key = "cn_" + configName;
            string str2 = "en_" + configName;
            return ((menuId == ConfigUtil.GetIntValue(key)) || (menuId == ConfigUtil.GetIntValue(str2)));
        }

        public bool IsCnSectionByMenuId(int menuId)
        {
            int cnOrEnRootId = this.GetCnOrEnRootId(menuId);
            return ((cnOrEnRootId == ConfigUtil.GetIntValue("cn_vwcar_id")) || (cnOrEnRootId == ConfigUtil.GetIntValue("cn_group")));
        }

        public string ListDir1(int DirID, string page_name)
        {
            int num3 = 1;
            string str2 = "";
            SysMenu menu = new SysMenu();
            IEnumerator enumerator = menu.getDir_List(DirID).GetEnumerator();
            while (enumerator.MoveNext())
            {
                SysMenuInfo current = (SysMenuInfo)enumerator.Current;
                int dirID = current.Node_ID;
                string str = current.Node_Name;
                if ((this.getRootID(DirID) == int.Parse(WebConfigurationManager.AppSettings["RootIDEN"])) && (str.Length >= 0x15))
                {
                    str = str.Substring(0, 0x15) + "-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + str.Substring(0x15, str.Length - 0x15);
                }
                for (int i = 0; i <= (this.jCount - 1); i++)
                {
                    int num5;
                    int num6;
                    object obj2;
                    if (this.iCount > 1)
                    {
                        if ((this.iCount > 1) && (num3 == 1))
                        {
                            str2 = str2 + "<table background=\"/pub/crm/images/sub_bg.gif\">";
                            num3++;
                        }
                        if (this.getDir_List(dirID).Count != 0)
                        {
                            str2 = str2 + "<tr><td width=\"174\"  height=\"20\" border=\"0\">";
                            if ((this.iCount - 1) != 0)
                            {
                                num5 = 0;
                                while (num5 < (this.iCount - 1))
                                {
                                    str2 = str2 + "<img src=\"/pub/crm/images/space_26x7.gif\" /><img src=\"/pub/crm/images/space_26x7.gif\" />";
                                    num5++;
                                }
                            }
                            obj2 = str2 + "<img src=\"/pub/crm/images/sub_arrow_off.gif\" />";
                            str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class = subnav>", str, "</a></td></tr>" });
                        }
                        else
                        {
                            if (this.menuuid == dirID)
                            {
                                str2 = str2 + "<tr><td width=\"170\" class=\"title_iframe\" bgcolor=\"#FFFFFF\" border=\"0\">";
                            }
                            else
                            {
                                str2 = str2 + "<tr><td width=\"174\" border=\"0\">";
                            }
                            num6 = 0;
                            while (num6 < this.iCount)
                            {
                                str2 = str2 + "<img src=\"/pub/crm/images/space_26x7.gif\" />";
                                num6++;
                            }
                            if (this.menuuid == dirID)
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class =\"title_iframe\">", str, "</a></td></tr>" });
                            }
                            else
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class =\"subnav\">", str, "</a></td></tr>" });
                            }
                        }
                        if ((this.iCount > 1) && (num3 == 1))
                        {
                            str2 = str2 + "</table>";
                        }
                    }
                    else
                    {
                        str2 = str2 + "<table width=\"175\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                        if (this.getDir_List(dirID).Count != 0)
                        {
                            str2 = str2 + "<tr><td width=\"174\" height=\"20\" border=\"0\">";
                            if ((this.iCount - 1) != 0)
                            {
                                for (num5 = 0; num5 < (this.iCount - 1); num5++)
                                {
                                    str2 = str2 + "<img src=\"/pub/crm/images/space_26x7.gif\" /><img src=\"/pub/crm/images/space_26x7.gif\" />";
                                }
                            }
                            str2 = str2 + "<img src=\"/pub/crm/images/sub_arrow_off.gif\" />";
                            if (this.menuuid == dirID)
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class =\"title_iframe\">", str, "</a></td></tr><tr><td height=\"1\" background=\"/pub/crm/images/dot.gif\"></td></tr>" });
                            }
                            else
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class =\"subnav\">", str, "</a></td></tr><tr><td height=\"1\" background=\"/pub/crm/images/dot.gif\"></td></tr>" });
                            }
                        }
                        else
                        {
                            str2 = str2 + "<tr><td width=\"174\" height=\"20\" border=\"0\">";
                            for (num6 = 0; num6 < this.iCount; num6++)
                            {
                                str2 = str2 + "<img src=\"/pub/crm/images/space_26x7.gif\" />";
                            }
                            if (this.menuuid == dirID)
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class =\"title_iframe\">", str, "</a></td></tr><tr><td height=\"1\" background=\"/pub/crm/images/dot.gif\"></td></tr>" });
                            }
                            else
                            {
                                obj2 = str2;
                                str2 = string.Concat(new object[] { obj2, "<a href =\"", page_name, "?menu_uid=", dirID, "\" class = subnav>", str, "</a></td></tr><tr><td height=\"1\" background=\"/pub/crm/images/dot.gif\"></td></tr>" });
                            }
                        }
                        str2 = str2 + "</table>";
                    }
                }
                if (dirID == this.DirList[this.DirCount])
                {
                    this.iCount++;
                    this.DirCount--;
                    str2 = str2 + this.ListDir1(dirID, page_name);
                    this.iCount--;
                }
                DirID = dirID;
            }
            return str2;
        }

        public bool ModifyByIdentity(SysMenuInfo data)
        {
            bool ret = false;
            int returnvalue = 0;
            string tmpSQL = "";
            tmpSQL = "UPDATE SYS_MENU SET             MENU_PARENT_UID=@MENU_PARENT_UID,            MENU_SORD=@MENU_SORD,            MENU_NAME=@MENU_NAME,            MENU_DISPLAY_NAME=@MENU_DISPLAY_NAME,            MENU_LINK=@MENU_LINK,            MENU_IS_LEAF=@MENU_IS_LEAF,            MENU_VALID=@MENU_VALID,            MENU_UPDATE_DATE=getDate(),            Tem_ID=@Tem_ID,            Tem_list_id=@Tem_list_id,            MENU_TYPE=@MENU_TYPE,            Menu_out_url=@Menu_out_url,            TARGET=@TARGET,            MENU_ICON=@MENU_ICON,            MENU_ICON1=@MENU_ICON1            ,MENU_ICON2=@MENU_ICON2,            MENU_OTHER=@MENU_OTHER WHERE MENU_UID=@MENU_UID";

            SqlParameter[] cellParms = {
				new SqlParameter("@MENU_UID",SqlDbType.Int,10),
                new SqlParameter("@MENU_PARENT_UID",SqlDbType.Int,10),
				new SqlParameter("@MENU_SORD",SqlDbType.Int,10),
				new SqlParameter("@MENU_NAME",SqlDbType.VarChar,255),
                new SqlParameter("@MENU_DISPLAY_NAME",SqlDbType.VarChar,255),
                new SqlParameter("@MENU_LINK",SqlDbType.VarChar,255),
                new SqlParameter("@MENU_IS_LEAF",SqlDbType.Char,1),
				new SqlParameter("@MENU_VALID",SqlDbType.Char,1),
				new SqlParameter("@Tem_ID",SqlDbType.Int,10),
				new SqlParameter("@Tem_list_id",SqlDbType.Int,10),
				new SqlParameter("@MENU_TYPE",SqlDbType.Char,1),
				new SqlParameter("@Menu_out_url",SqlDbType.VarChar,255),
				new SqlParameter("@TARGET",SqlDbType.VarChar,50),
				new SqlParameter("@MENU_ICON",SqlDbType.VarChar,50),
				new SqlParameter("@MENU_ICON1",SqlDbType.VarChar,50),
				new SqlParameter("@MENU_ICON2",SqlDbType.VarChar,50),
				new SqlParameter("@MENU_OTHER",SqlDbType.VarChar,50)
            };
            cellParms[0].Value = data.Node_ID;
            cellParms[1].Value = data.Parent_Node_ID;
            cellParms[2].Value = data.Menu_Sord;
            cellParms[3].Value = data.Node_Name;
            cellParms[4].Value = data.Node_Desc;
            cellParms[5].Value = data.Link;
            cellParms[6].Value = data.IsLeaf;
            cellParms[7].Value = data.Menu_Valid;
            cellParms[8].Value = data.Tem_ID;
            cellParms[9].Value = data.Tem_list_ID;
            cellParms[10].Value = data.Menu_Type;
            cellParms[11].Value = data.Menu_out_url;
            cellParms[12].Value = data.target;
            cellParms[13].Value = data.MENU_ICON;
            cellParms[14].Value = data.MENU_ICON1;
            cellParms[15].Value = data.MENU_ICON2;
            cellParms[16].Value = data.MENU_OTHER;

            using (SqlConnection conn = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        returnvalue = SQLHelper.ExecuteNonQuery(trans, CommandType.Text, tmpSQL, cellParms);
                        trans.Commit();
                        if (returnvalue > 0)
                            ret = true;
                    }
                    catch (SqlException err)
                    {
                        trans.Rollback();
                        System.Console.WriteLine(err.Message);
                    }
                }
            }
            return ret;
        }

        public void ModifyMenu(SysMenuInfo myItem)
        {
            SqlParameter[] menuModifyParameters = GetMenuModifyParameters();
            this.SetMenuModifyParameters(menuModifyParameters, myItem);
            using (SqlConnection connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC))
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        SQLHelper.ExecuteNonQuery(transaction, CommandType.Text, "UPDATE Sys_Menu SET Menu_Parent_UID = @Menu_Parent_UID, Menu_Sord = @Menu_Sord, Menu_Name = @Menu_Name, Menu_Display_Name = @Menu_Display_Name, Menu_Link = @Menu_Link, Menu_Is_Leaf = @Menu_Is_Leaf, Menu_Update_Date = getDate(), Menu_Valid = @Menu_Valid,Tem_ID=@Tem_ID,Tem_list_id=@Tem_list_id,MENU_TYPE=@menu_type,Menu_out_url=@menu_out_url,TARGET=@target, MENU_ICON=@MENU_ICON, MENU_ICON1=@MENU_ICON1, MENU_ICON2=@MENU_ICON2, MENU_OTHER=@MENU_OTHER WHERE Menu_UID = @Menu_UID", menuModifyParameters);
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }

        public int Select(string menu_name)
        {
            int num = 0;
            string cmdText = "select menu_uid,menu_name from sys_menu where menu_name='" + menu_name + "'";
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    SysMenuInfo info2 = new SysMenuInfo(reader.GetInt32(0));
                    num = info2.Menu_uid;
                }
            }
            return num;
        }

        public int ParentID(string menu_name)
        {
            int num = 0;
            string cmdText = "select MENU_PARENT_UID from sys_menu where menu_name='" + menu_name + "'";
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    num = reader.GetInt32(0);
                }
            }
            return num;
        }

        public int PageID(string menu_id)
        {
            int num = 0;
            string cmdText = "SELECT menu_id FROM lalel_config_info WHERE (menu_parent_id = " + menu_id + ") AND (label_id = 1)";
            SqlParameter[] cmdParms = new SqlParameter[0];
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, cmdParms))
            {
                while (reader.Read())
                {
                    num = reader.GetInt32(0);
                }
            }
            return num;
        }

        private void SetItemParametersID(SqlParameter[] parms, ItemInfo acc)
        {
            parms[0].Value = acc.Node_ID;
            parms[1].Value = acc.Parent_Node_ID;
            parms[2].Value = acc.Node_Name;
            parms[3].Value = acc.Node_Desc;
        }

        private void SetMenuInsertParameters(SqlParameter[] parms, SysMenuInfo acc)
        {
            parms[0].Value = acc.Parent_Node_ID;
            parms[1].Value = acc.Menu_Sord;
            parms[2].Value = acc.Node_Name;
            parms[3].Value = acc.Node_Desc;
            parms[4].Value = acc.Link;
            parms[5].Value = acc.IsLeaf;
            parms[6].Value = acc.Menu_Valid;
            parms[7].Value = acc.Tem_ID;
            parms[8].Value = acc.Tem_list_ID;
            parms[9].Value = acc.Menu_Type;
            parms[10].Value = acc.Menu_out_url;
            parms[11].Value = acc.target;
        }

        private void SetMenuModifyParameters(SqlParameter[] parms, SysMenuInfo acc)
        {
            parms[0].Value = acc.Node_ID;
            parms[1].Value = acc.Parent_Node_ID;
            parms[2].Value = acc.Menu_Sord;
            parms[3].Value = acc.Node_Name;
            parms[4].Value = acc.Node_Desc;
            parms[5].Value = acc.Link;
            parms[6].Value = acc.IsLeaf;
            parms[7].Value = acc.Menu_Valid;
            parms[8].Value = acc.Tem_ID;
            parms[9].Value = acc.Tem_list_ID;
            parms[10].Value = acc.Menu_Type;
            parms[11].Value = acc.Menu_out_url;
            parms[12].Value = acc.target;
            parms[13].Value = acc.MENU_ICON;
            parms[14].Value = acc.MENU_ICON1;
            parms[15].Value = acc.MENU_ICON2;
            parms[16].Value = acc.MENU_OTHER;
        }

        private void SetNavigationList(IList list, IList navigations, SysMenuInfo smi, int siteRootId)
        {
            navigations.Insert(0, smi);
            foreach (SysMenuInfo info in list)
            {
                if (info.Node_ID == smi.Parent_Node_ID)
                {
                    if (info.Node_ID != siteRootId)
                    {
                        this.SetNavigationList(list, navigations, info, siteRootId);
                    }
                    break;
                }
            }
        }

        private void SetNodeRootId(IList list, int siteRootId, ref SysMenuInfo info)
        {
            if (info.Parent_Node_ID != siteRootId)
            {
                foreach (SysMenuInfo info2 in list)
                {
                    if (info2.Node_ID == info.Parent_Node_ID)
                    {
                        info = info2;
                        this.SetNodeRootId(list, siteRootId, ref info);
                        break;
                    }
                }
            }
        }

        public IList GetAllMenuOther(int menu_id)
        {
            //int menu_parent_id = this.getLeftMenuParentID(menu_id);

            string cmdText = "select menu_uid, menu_parent_uid, menu_name, tem_id, tem_list_id, menu_type, menu_out_url, isnull(target, '_self') as target from sys_menu where isdel = '0' and menu_parent_uid=" + menu_id.ToString() + " order by menu_sord";
            IList list = new ArrayList();
            SysMenuInfo info = null;
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_NON_DTC, CommandType.Text, cmdText, null))
            {
                while (reader.Read())
                {
                    info = new SysMenuInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2), "");
                    info.Menu_uid = reader.GetInt32(0);
                    info.Menu_name = reader.GetString(2);
                    info.Tem_ID = reader.GetInt32(3);
                    info.Tem_list_ID = reader.GetInt32(4);
                    info.Menu_Type = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                    {
                        info.Menu_out_url = reader.GetString(6);
                    }
                    info.target = reader.GetString(7);
                    list.Add(info);
                }
            }
            return list;
        }
    }
}
